home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / alv.sun / alv.lha / src / ras2lw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-08  |  3.0 KB  |  132 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "defs.h"
  4.  
  5. #define MIDX        285        /* center of output page */
  6. #define MIDY        396
  7.  
  8. ixrect        *pr;
  9. har           *progname;
  10. har           *filename;
  11. nt             small, large, mail, special, nopipe;
  12. har           *title;
  13.  
  14. #ifdef STANDALONE
  15. ain(argc, argv, envp)
  16. #else
  17. as2lw_main(argc, argv, envp)
  18. #endif
  19.     int             argc;
  20.     char          **argv;
  21.     char          **envp;
  22. {
  23.     int             c, x = 0, y = 0, r = 0;
  24.     register int    i, j;
  25.     double          sx = 1.0, sy = 1.0, atof();
  26.     char           *hex();
  27.     char            buf1[BUFSIZ];
  28.     FILE           *pd;
  29.  
  30.     small = TRUE;
  31.     large = mail = special = nopipe = FALSE;
  32.  
  33.     progname = strsave(argv[0]);
  34.     parse_profile(&argc, argv, envp);
  35.  
  36.     title = NULL;
  37.  
  38.     while ((gc = getopt(argc, argv, "mslt:T")) != EOF)
  39.         switch (gc) {
  40.         case 'm':
  41.             mail = TRUE;
  42.             break;
  43.         case 's':
  44.             small = TRUE;
  45.             break;
  46.         case 'l':
  47.             large = TRUE;
  48.             break;
  49.         case 't':
  50.             title = strsave(optarg);
  51.             break;
  52.         case 'T':
  53.             special = TRUE;
  54.             nopipe = TRUE;
  55.             break;
  56.         case '?':
  57.             errflag++;
  58.             break;
  59.         }
  60.  
  61.     if (errflag)
  62.         error((char *) 0, "Usage: %s: [-s] [-l] [-m] [-t title] [-T] [infile]\n", progname);
  63.  
  64.     for (stream = 0; optind < argc; stream++, optind++)
  65.         if (stream == 0 && strcmp(argv[optind], "-") != 0)
  66.             if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
  67.                 error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
  68.  
  69.     if ((pr = pr_load(stdin, NULL)) == NULL)
  70.         error(PR_IO_ERR_RASREAD);
  71.  
  72.     if (pr->pr_depth > 8)
  73.         error("Cannot print images with depth greater than 8 bits");
  74.  
  75.     if (!nopipe) {
  76.         if ((pd = popen(strcat("lpr -Plw -v", ((mail) ? " -m" : "")), "w")) == NULL)
  77.             error("Cannot open pipe to lpr");
  78.     } else
  79.         pd = stdout;
  80.  
  81.     fprintf(pd, "%%!PS-Adobe-1.0\n");    /* PostScript magic strings */
  82.     fprintf(pd, "/picstr %d string def\n", pr->pr_size.x);
  83.  
  84.     if (title) {
  85.         fprintf(pd, "/Helvetica-Bold findfont\n");
  86.         fprintf(pd, "12 scalefont setfont\n");
  87.         fprintf(pd, "285 (%s) stringwidth pop 2 div sub 720 moveto\n", title);
  88.         fprintf(pd, "(%s) show\n", title);
  89.     }
  90.     if (small || large) {
  91.         sx = 7.91 * 300 / pr->pr_size.x;
  92.         sy = 8.5 * 300 / pr->pr_size.y;    /* avoid title area */
  93.         if (large) {
  94.             sx /= 2.;
  95.             sy /= 2.;
  96.         }
  97.         sx = sy = (sx > sy) ? sy : sx;
  98.         x = -sx * pr->pr_size.x * 72 / 300 / 2;
  99.         y = -sy * pr->pr_size.y * 72 / 300 / 2;
  100.     }
  101.     if (special)
  102.         fprintf(pd, " 0 0 translate\n");
  103.     else
  104.         fprintf(pd, "%d %d translate\n", MIDX + x, MIDY - 36 + y);
  105.  
  106.     fprintf(pd, "%d %d scale\n", (int) (pr->pr_size.x / 300.0 * 72.0 * sx), (int) (pr->pr_size.y / 300.0 * 72.0 * sy));
  107.     fprintf(pd, "%d %d 8\n", pr->pr_size.x, pr->pr_size.y);
  108.     fprintf(pd, "[ %d 0 0 -%d 0 %d ]\n", pr->pr_size.x, pr->pr_size.y, pr->pr_size.y);
  109.     fprintf(pd, "{currentfile\npicstr readhexstring pop}\nimage\n");
  110.  
  111.     for (j = 0; j < pr->pr_size.y; j++)
  112.         for (i = 0; i < pr->pr_size.x; i++) {
  113.             if (nopipe && !(i % 40))
  114.                 fputs("\n", pd);
  115.             fputs(hex(pr_get(pr, i, j)), pd);
  116.             }
  117.  
  118.     if (!special)
  119.         fprintf(pd, "showpage\n");
  120.     if (!nopipe)
  121.         pclose(pd);
  122. }
  123.  
  124. har           *
  125. ex(d)
  126. {
  127.     static char     a[10];
  128.  
  129.     sprintf(a, "%02x", d);
  130.     return (a);
  131. }
  132.